import { defineConfig } from "vite";
import { viteCommonjs } from "@originjs/vite-plugin-commonjs";
import commonjs from "@rollup/plugin-commonjs";
import path from "path";
export default defineConfig({
  server: {
    host: "0.0.0.0",
    port: 5000,
    open: true,
  },
  publicDir: "dist",
  base: "./",
  build: {
    outDir: "dist",
    emptyOutDir: true, //构建前是否清空outDir
    cssCodeSplit: true, //是否拆分css,lib模式永远抽离到单独的css文件内
    sourcemap: true, //是否开启源码映射
    // minify: false, //是否开启代码压缩 true/false
    lib: {
      entry: path.resolve(__dirname, "./src/less-browser.js"),
      name: "LessBrowser",
      fileName: "less-browser",
      formats: ["umd"], // ['es', 'umd']
    },
  },
  define: { "process.env": {} }, //去除编译后process报错的问题
  plugins: [
    viteCommonjs(), //开发环境使用commonjs
    commonjs({ requireReturnsDefault: false }), // 配置requireReturnsDefault:true属性，//解决引入commonjs模块后打包出现的{'default' is not exported by XXX}错误!!
  ],
});
